pub fn contains_nearby_duplicate(nums: Vec<i32>, k: i32) -> bool {
    use std::collections::HashMap;
    let mut map = HashMap::new();

    for i in 0..nums.len() {
        let num = nums[i];
        match map.get(&num) {
            Some(last_i) => {
                if i - last_i <= k as usize {
                    return true;
                }
            }
            None => {}
        };
        map.insert(num, i);
    }

    return false;
}
